//floortrap.txt - A trap blocking a corridor. Booms or is disarmed when used. This
// is the defautl script type of floor trap objects (types 49-52) and should
// not be given to any other object.

//Cell 0 - Difficulty of trap.
//Cell 1 - The effect created.
//  0 - fiery boom
//  1 - magical boom 
//  2 - spray acid
//  3 - spray poison
//  4 - alarm
//  5 - summon monst (damage of trap is mob id to summon)
//  6 - create group (damage of trap is group to activate)
//Cell 2,3 - The sdf which is set to 1 when box is unlocked.
//Cell 4 - The damage of the trap (either d8 of damage or exact amount of status).

beginobjectscript;

variables;
	short trap_is_gone = 0;
	short got_warning = 0;
	short r1;
	short trap_level = 6;
	
body;

beginstate INIT_STATE;
	if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
		if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0)
			kill_object(ME,0);
		}
	if (get_memory_cell(4) > 0)	
		trap_level = get_memory_cell(4);
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE;
	if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
		if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0)
			kill_object(ME,0);
		}

break;

beginstate USE_STATE;
	if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
		if (get_sdf(get_memory_cell(2),get_memory_cell(3)) > 0)
			trap_is_gone = 1;
		}
		
	if (trap_is_gone == 0) {
		if (get_stat_total(24) >= get_memory_cell(0)) {
			print_str("Disarm Trap: You are able to disarm it.");
			trap_is_gone = 1;
			kill_object(ME,0);
			play_sound(29);

			if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) {
				if (get_flag(get_memory_cell(2),get_memory_cell(3)) == 0)
					award_party_xp(BASE_TRAP_XP,get_memory_cell(0));
				set_flag(get_memory_cell(2),get_memory_cell(3),1);
				}
			}
			else if (got_warning == 0) {
				print_str("Disarm Trap: You are able to tell that it has a trap, but your");
				print_str("  Tool Use skill isn't high enough to disarm it. Try again to");
				print_str("  proceed anyway.");
				got_warning = 1;
				end();
				}
				else { // trigger trap
					print_str("Disarm Trap: You set off a trap!");
					trap_is_gone = 1;
					if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0))
						set_flag(get_memory_cell(2),get_memory_cell(3),1);
					if (get_memory_cell(1) == 0) { // fire boom
						r1 = get_ran(trap_level,1,8);
						run_sparkles_on_object(ME,173,1,4);
						spray_missiles(51,8,8);
						damage_char(30000,r1,2);
						play_sound(159);
						}
					if (get_memory_cell(1) == 1) { // magic boom
						r1 = get_ran(trap_level,1,8);
						run_sparkles_on_object(ME,162,1,4);
						spray_missiles(54,8,8);
						damage_char(30000,r1,1);
						play_sound(173);
						}
					if (get_memory_cell(1) == 2) { // acid boom
						r1 = trap_level;
						run_sparkles_on_object(ME,12,9,1);
						spray_missiles(52,8,8);
						set_char_status(30000,6,r1);
						play_sound(178);
						}
					if (get_memory_cell(1) == 3) { // poison boom
						r1 = trap_level;
						run_sparkles_on_object(ME,13,9,1);
						spray_missiles(52,8,8);
						set_char_status(30000,2,r1);
						play_sound(178);
						}
					if (get_memory_cell(1) == 4) { // alarm
						print_str_color("An alarm goes off! The area is alerted!",1);
						change_crime_level(-1,5);
						play_sound(179);
						}
					if (get_memory_cell(1) == 5) { // monst summoned
						print_str_color("The trap shoots out a cloud of mist. It forms into a creature!",1);
						spawn_creature(get_memory_cell(4));
						set_boss_level(get_memory_cell(4),1);
						set_summon_level(get_memory_cell(4),1);
						play_sound(171);
						}
					if (get_memory_cell(1) == 6) { // group created
						print_str_color("The trap shoots out a cloud of mist. It forms into several creatures!",1);
						activate_hidden_group(get_memory_cell(4));
						play_sound(171);
						}
					kill_object(ME,0);
					//if ((object_type(ME) == 49) || (object_type(ME) == 50))
					//	set_object_icon(ME,8);
					//if (object_type(ME) == 51)
					//	set_object_icon(ME,10);
					//if (object_type(ME) == 52)
					//	set_object_icon(ME,12);
					//set_object_blockage(ME,0);
					end();
					}
		}		

break;


beginstate UNLOCK_STATE;
	if (trap_is_gone == 0) {
		print_str("Unlock Spell: An area of the floor nearby glows. It must have a trap.");
		}
break;

